
/* ************************************************************************************* 
 * CREATED BY:          MYGENERATION
 * CREATED DATE:        12/25/2008
 * PROJECT:             MCWEBSITE
 * PURPOSE:             websiteResourceTypeDAL class
 * MODIFIED BY:         None
 * MODIFIED DATE:       None
 * MODIFIED REASON:     None
 * NOTES:               None
 **************************************************************************************/
 
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Web.Configuration;
using MCWEBSITE.ENTITY;

namespace MCWEBSITE.DAL
{
    public class websiteResourceTypeDAL
    {
        #region  Properties
		 
		public static string FIELD_RESOURCETYPEID = "ResourceTypeID";  
		public static string FIELD_LANGUAGECODE = "LanguageCode";  
		public static string FIELD_RESOURCETYPECODE = "ResourceTypeCode";  
		public static string FIELD_TYPENAME = "TypeName";  
		public static string FIELD_DESCRIPTION = "Description";  
		public static string FIELD_ATRIBUTE1 = "Atribute1";  
		public static string FIELD_ATRIBUTE2 = "Atribute2";  
		public static string FIELD_ATRIBUTE3 = "Atribute3"; 
		public static string ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ContentConnectionString"].ToString();

        #endregion

        #region Protected methods

        /// <summary>
        /// Select entity of websiteResourceType
        /// </summary>
        /// <param name="ResourceTypeID">Primary Keys</param>
        /// <returns>Collection of websiteResourceTypeInfo</returns>
        public static websiteResourceTypeInfo SelectOne(int ResourceTypeID)
        {
            websiteResourceTypeInfo _websiteResourceTypeInfo = new websiteResourceTypeInfo();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteResourceTypeSelectOne", ResourceTypeID);
                if (dr.Read())
                    setwebsiteResourceTypeInfo(dr, ref _websiteResourceTypeInfo);
                return _websiteResourceTypeInfo;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select all websiteResourceType
        /// </summary>
        /// <returns>Collection of websiteResourceTypeInfo</returns>
        public static List<websiteResourceTypeInfo> SelectAll()
        {
            List<websiteResourceTypeInfo> lstwebsiteResourceType = new List<websiteResourceTypeInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteResourceTypeSelectAll");
                setListwebsiteResourceTypeInfo(ref dr, ref lstwebsiteResourceType);
                return lstwebsiteResourceType;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select
        /// </summary>
        /// <param name="websiteResourceTypenfo">Modify this method adapting your need</param>
        /// <returns>Collection of websiteResourceTypeInfo</returns>
        public static List<websiteResourceTypeInfo> SelectFilters()
        {
            string criterias = string.Empty;
            List<websiteResourceTypeInfo> lstwebsiteResourceType = new List<websiteResourceTypeInfo>();
            SqlDataReader dr = null;
            try 
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteResourceTypeSelectByFilters");
                setListwebsiteResourceTypeInfo(ref dr, ref lstwebsiteResourceType);
                return lstwebsiteResourceType;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Insert websiteResourceType
        /// </summary>
        /// <param name="websiteResourceTypeInfo">Entity of websiteResourceType</param>
        /// <returns>error code</returns>
        public static int Insert(websiteResourceTypeInfo _websiteResourceTypeInfo)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteResourceTypeInsert" 
											, _websiteResourceTypeInfo.LanguageCode
											, _websiteResourceTypeInfo.ResourceTypeCode
											, _websiteResourceTypeInfo.TypeName
											, _websiteResourceTypeInfo.Description
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        
        /// <summary>
        /// Update websiteResourceType
        /// </summary>
        /// <param name="websiteResourceTypeInfo">Entity of websiteResourceType</param>
        /// <returns>error code</returns>
        public static int Update(websiteResourceTypeInfo _websiteResourceTypeInfo)
        {            
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteResourceTypeUpdate"
											, _websiteResourceTypeInfo.ResourceTypeID
											, _websiteResourceTypeInfo.LanguageCode
											, _websiteResourceTypeInfo.ResourceTypeCode
											, _websiteResourceTypeInfo.TypeName
											, _websiteResourceTypeInfo.Description
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// Delete SchoolAdmin
        /// </summary>
        /// <param name="ResourceTypeID">Primary Key</param>
        /// <returns>error code</returns>
        public static int Delete(int ResourceTypeID)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteResourceTypeDelete", ResourceTypeID);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        #endregion

        #region "Utilities method"
		
        private static void setListwebsiteResourceTypeInfo(ref SqlDataReader dr, ref List<websiteResourceTypeInfo> lstwebsiteResourceType)
        {
            websiteResourceTypeInfo _websiteResourceTypeInfo = null;
            while (dr.Read())
            {
                _websiteResourceTypeInfo = new websiteResourceTypeInfo();
                setwebsiteResourceTypeInfo(dr, ref _websiteResourceTypeInfo);
                lstwebsiteResourceType.Add(_websiteResourceTypeInfo);
            }
        }

        private static void setwebsiteResourceTypeInfo(SqlDataReader dr, ref websiteResourceTypeInfo _websiteResourceTypeInfo)
        {
            _websiteResourceTypeInfo.ResourceTypeID = dr[websiteResourceTypeDAL.FIELD_RESOURCETYPEID] != DBNull.Value ? Convert.ToInt32(dr[websiteResourceTypeDAL.FIELD_RESOURCETYPEID]) : 0;
			_websiteResourceTypeInfo.LanguageCode = dr[websiteResourceTypeDAL.FIELD_LANGUAGECODE] != DBNull.Value ? Convert.ToString(dr[websiteResourceTypeDAL.FIELD_LANGUAGECODE]) : string.Empty;
			_websiteResourceTypeInfo.ResourceTypeCode = dr[websiteResourceTypeDAL.FIELD_RESOURCETYPECODE] != DBNull.Value ? Convert.ToString(dr[websiteResourceTypeDAL.FIELD_RESOURCETYPECODE]) : string.Empty;
			_websiteResourceTypeInfo.TypeName = dr[websiteResourceTypeDAL.FIELD_TYPENAME] != DBNull.Value ? Convert.ToString(dr[websiteResourceTypeDAL.FIELD_TYPENAME]) : string.Empty;
			_websiteResourceTypeInfo.Description = dr[websiteResourceTypeDAL.FIELD_DESCRIPTION] != DBNull.Value ? Convert.ToString(dr[websiteResourceTypeDAL.FIELD_DESCRIPTION]) : string.Empty;
			_websiteResourceTypeInfo.Atribute1 = dr[websiteResourceTypeDAL.FIELD_ATRIBUTE1] != DBNull.Value ? Convert.ToString(dr[websiteResourceTypeDAL.FIELD_ATRIBUTE1]) : string.Empty;
			_websiteResourceTypeInfo.Atribute2 = dr[websiteResourceTypeDAL.FIELD_ATRIBUTE2] != DBNull.Value ? Convert.ToString(dr[websiteResourceTypeDAL.FIELD_ATRIBUTE2]) : string.Empty;
			_websiteResourceTypeInfo.Atribute3 = dr[websiteResourceTypeDAL.FIELD_ATRIBUTE3] != DBNull.Value ? Convert.ToString(dr[websiteResourceTypeDAL.FIELD_ATRIBUTE3]) : string.Empty;
			                        
        }
        #endregion Methods

        #region Private Members

        private static string TABLE_NAME = "[mc_websiteResourceType]";

        #endregion
    }
}

		